package leetcode100;

import java.util.LinkedList;

public class lc013 {
    public static void main(String[] args) {
        Tree tree = new Tree();
        TreeNode root = tree.root;
        tree.visit();
        int depth = maxDepth(root);
        System.out.println("depth = " + depth);
    }

    public static int maxDepth(TreeNode root) {
        if(root == null ) return 0;
        LinkedList<TreeNode> queue = new LinkedList<>();
        LinkedList<TreeNode> tempQueue = new LinkedList<>();
        int count=0;

        queue.add(root);
        while(!queue.isEmpty()) {
            tempQueue.addAll(queue);
            queue.clear();
            for (TreeNode cur : tempQueue) {
                if(cur.left!=null) queue.add(cur.left);
                if(cur.right!=null) queue.add(cur.right);
            }
            tempQueue.clear();
            count++;
        }
        return count;
    }
}
